package pri.lt.parser;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;

public class WebDriverWrapper {

    public boolean isInUse() {
        return inUse;
    }

    public void setInUse(boolean inUse) {
        this.inUse = inUse;
    }

    private boolean inUse;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setWebDriver(WebDriver webDriver) {
        this.webDriver = webDriver;
    }

    private int id;
    private WebDriver webDriver;

    public WebDriver getWebDriver() {
        return webDriver;
    }

    public void release() {
        WebDriverManager.release(this);
    }

    public String getHtmlExcuteJs() {
        if (webDriver instanceof PhantomJSDriver) {
            return (String)((PhantomJSDriver)webDriver).executeScript("return document.documentElement.outerHTML","");
            //return webDriver.getPageSource();
        } else {
            return webDriver.getPageSource();
        }
    }



    public void scroll(int i) {

        if (webDriver instanceof PhantomJSDriver) {
            ((PhantomJSDriver) webDriver).executeScript("var q=document.documentElement.scrollTop=" + i);
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}
